import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/welcome/Welcome.vue'
import SystemMenu from '../components/system/menu/index.vue'
import SystemMenuBaseCommon from '../components/system/baseCommon/index.vue'
import User from '../components/system/user/index.vue'
// 基础
import CapitalAccount from '../components/base/capitalAccount/index.vue'
import OutMoneyType from '../components/base/outMoneyType/index.vue'
import OutMoneyClass from '../components/base/outMoneyClass/index.vue'
import InMoneyType from '../components/base/inMoneyType/index.vue'
// 收支
import InMoney from '../components/inOut/inMoney/index.vue'
import OutMoney from '../components/inOut/outMoney/index.vue'
import BorrowMoney from '../components/inOut/borrowMoney/index.vue'
import TransferMoney from '../components/inOut/transferMoney/index.vue'



Vue.use(VueRouter)
const router = new VueRouter({
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/home',
      component: Home,
      children: [
        { path: '/welcome', component: Welcome },
        { path: '/system/menu', component: SystemMenu },
        { path: '/system/baseCommon', component: SystemMenuBaseCommon },
        { path: '/system/user', component: User },
        { path: '/base/capitalAccount', component: CapitalAccount },
        { path: '/base/outMoneyType', component: OutMoneyType },
        { path: '/base/outMoneyClass', component: OutMoneyClass },
        { path: '/base/inMoneyType', component: InMoneyType },
        { path: '/inOut/inMoney', component: InMoney },
        { path: '/inOut/outMoney', component: OutMoney },
        { path: '/inOut/borrowMoney', component: BorrowMoney },
        { path: '/inOut/transferMoney', component: TransferMoney }
      ]
    }
  ]
})

// 挂载路由导航首位
router.beforeEach((to, from, next) => {
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})

export default router
